home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8411.arc
/
SAVEBAS.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-09-14
|
3KB
|
65 lines
;----------------------------------------------------------------------
;SAVEBAS.COM by Dan Rollins 01/22/84
;
; This program will create a file from a BASIC program that was "lost"
; through an inadvertent use of the SYSTEM command. After making that
; mistake, execute this program and the lost program will be saved
; to the default directory as %SAVED.BAS. It should then be saved and
; reloaded before it is edited.
;
; Notes: This program works only for DOS 2.0 or later.
; It must be executed IMMEDIATELY after exiting from BASIC--
; before loading or running any program, especially BASIC!
;
; This is a .COM program, so you must assemble, link, and
; EXE2BIN
;
com_seg segment
assume cs:com_seg,ds:com_seg
org 100H
begin:
jmp code_start
filename db '%SAVED.BAS',0 ;ASCIIZ string of filename
err_msg db 'File error encountered '
db 'while writing to %SAVED.BAS ',0DH,0AH,'$'
ok_msg db 'BASIC program file saved in %SAVED.BAS',0DH,0AH,'$'
code_start:
mov dx,offset filename ;point to ASCIIZ string w/ filespec
mov cx,0 ;file attribute = read/write
mov ah,3cH
int 21H ;DOS 2.0 CREATE file-handle service
jc file_err ;exit if error return
mov bx,ax ;save file handle in BX
mov ax,0
mov ds,ax
mov ax,word ptr ds:[510H] ;fetch BASIC segment at 0000:0510
mov ds,ax ;DS => BASIC program segment
mov si,word ptr ds:[30H] ;fetch start of the lost program
dec si ;point to 1-byte before it and
mov byte ptr [si],0FFH ;place the token-file header byte
mov cx,word ptr ds:[358H] ;fetch end of the lost program
sub cx,si ;CX = length of the lost program
mov dx,si ;DX is offset of first byte to write
mov ah,40H ;DOS 2.00 WRITE_HANDLE service
int 21H ;write CX bytes starting at DS:DX
; to file handle BX
jc file_err ;exit if error
mov ah,3EH
int 21H ;close the file handle in BX
mov dx,offset ok_msg ;indicate all OK
jmp short exit
file_err:
mov dx,offset err_msg
exit:
push cs
pop ds ;make sure DS:DX points to message
mov ah,9
int 21H ;write the message at DS:DX
int 20H ;exit to DOS
com_seg ends
end begin